#include<iostream>
using namespace std;
#include<vector>
void xuanzhuan(vector<vector<int>>& matrix, int n) {
    for (int i = 0; i < n / 2; ++i) {
        for (int j = 0; j < n; ++j) {
            swap(matrix[i][j], matrix[n - i - 1][n - j - 1]);
        }
    }
    if (n % 2) {
        for (int i = 0; i < n / 2; ++i)
            swap(matrix[n / 2][i], matrix[n / 2][n - i - 1]);
    }
}
void jingxiang(vector<vector<int>>& matrix, int n) {
    for (int i = 0; i < n / 2; ++i) {
        for (int j = 0; j < n; ++j) {
            swap(matrix[i][j], matrix[n - i - 1][j]);
        }
    }
}
int main() {
    int n;
    cin >> n;
    vector<vector<int>> matrix(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> matrix[i][j];
        }
    }
    int q;
    cin >> q;
    int one = 0, two = 0;
    while (q--) {
        int a;
        cin >> a;
        if (a == 1)
            ++one;
        else
            ++two;
    }
    one %= 2;
    two %= 2;
    if (one)
        xuanzhuan(matrix, n);
    if (two)
        jingxiang(matrix, n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << matrix[i][j] << ' ';
        }
        cout << endl;
    }
}